//
//  PushManageViewController.m
//  FootPrint
//
//  Created by 秦 东方 on 4/29/13.
//  Copyright (c) 2013 alex tao. All rights reserved.
//

#import "PushManageViewController.h"

@interface PushManageViewController ()

@end

@implementation PushManageViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    NSUserDefaults* data = [NSUserDefaults standardUserDefaults];
    self.arr = [data objectForKey:@"pushSetting"];
    if(self.arr == nil){
        self.arr = [NSMutableArray arrayWithObjects:[NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES], [NSNumber numberWithBool:YES], nil];
        [data setObject:self.arr forKey:@"pushSetting"];
    }
    
    _isPeople = [((NSNumber*)[self.arr objectAtIndex:0])boolValue ];
    _isAddr = [((NSNumber*)[self.arr objectAtIndex:1])boolValue ];
    _isTime = [((NSNumber*)[self.arr objectAtIndex:2])boolValue ];
    _isWeather = [((NSNumber*)[self.arr objectAtIndex:3])boolValue ];
    _isMerchant = [((NSNumber*)[self.arr objectAtIndex:4])boolValue ];
    _isNew = [((NSNumber*)[self.arr objectAtIndex:5])boolValue ];
    
    
    
    [_switchPeople setOn:_isPeople];
    [_switchAddr setOn:_isAddr];
    [_switchTime setOn:_isTime];
    [_switchWeather setOn:_isWeather];
    [_switchMerchant setOn:_isMerchant];
    [_switcNews setOn:_isNew];
       
    
}

- (IBAction)swichChanged:(id*)uiSwitch{

    UISwitch* swit = (UISwitch*)uiSwitch;
    int tag = swit.tag;
    BOOL value = swit.isOn;
    NSUserDefaults* data = [NSUserDefaults standardUserDefaults];
    switch (tag) {
        case 0:
            _isPeople = value;
            break;
        case 1:
            _isAddr = value;
            break;
        case 2:
            _isTime = value;
            break;
        case 3:
            _isWeather = value;
            break;
        case 4:
            _isMerchant = value;
            break;
        case 5:
            _isNew = value;
            break;
            
        default:
            break;
    }
    self.arr = [NSMutableArray arrayWithObjects:[NSNumber numberWithBool:_isPeople], [NSNumber numberWithBool:_isAddr], [NSNumber numberWithBool:_isTime], [NSNumber numberWithBool:_isWeather], [NSNumber numberWithBool:_isMerchant], [NSNumber numberWithBool:_isNew], nil];
    [data setObject:self.arr forKey:@"pushSetting"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)back:(id)sender {
    
    if (self.navigationController.viewControllers.count > 1) {
        [self.navigationController popViewControllerAnimated:YES];
    } else {
        [self.navigationController dismissModalViewControllerAnimated:YES];
    }
}
- (void)dealloc {
    [_switchPeople release];
    [_switchAddr release];
    [_switchTime release];
    [_switchWeather release];
    [_switchMerchant release];
    [_switcNews release];
    [super dealloc];
}
- (void)viewDidUnload {
    [self setSwitchPeople:nil];
    [self setSwitchAddr:nil];
    [self setSwitchTime:nil];
    [self setSwitchWeather:nil];
    [self setSwitchMerchant:nil];
    [self setSwitcNews:nil];
    [super viewDidUnload];
}
@end
